<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../3-swiper/dist/css/swiper.min.css">
    <script src="../3-swiper/dist/js/swiper.js"></script>
    <script src="../plugins/vue.global.js"></script>

</head>
<body>

    <div id="box">

        <div class="swiper-container">
        
            <div class="swiper-wrapper">
                <div class="swiper-slide" v-for="(data,index) in dataList" :key="data" v-counts="{index:index,lengths:dataList.length}">{{data}}</div>
            </div>
            {{myName}}
            <div class="swiper-pagination"></div>
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>
    
        </div>
    </div>
    

  
    <script>  
    let obj= {
      data(){
        return{
          dataList:[],
            myName:''
        }
      },
      mounted() {
        setTimeout(() => {
        this.dataList= ['11','22','33']
        }, 2000);
        }

    }

    let app = Vue.createApp(obj);
    app.directive('counts',{
      // Vue3中更改了名字
      mounted(el,binding){
        let {index,lengths} = binding.value;
        if(index == lengths -1){
          console.log(1111)
          var mySwiper = new Swiper ('.swiper-container', {
          loop: true, 
          pagination: {
            el: '.swiper-pagination',
          },
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          },
        }) 
        }
      }
    })
    app.mount('#box')
        </script>
</body>
</html>